<script setup lang="ts">
import {useAccount} from "./utils/hook";
import {computed, nextTick, onMounted, ref} from "vue";
import {PureTableBar} from "@/components/RePureTableBar";
import {useRenderIcon} from "@/components/ReIcon/src/hooks";
import {deviceDetection, useResizeObserver} from "@pureadmin/utils";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
import { useRoute } from 'vue-router'
const route = useRoute()
import Refresh from "@iconify-icons/ep/refresh";
import Close from "@iconify-icons/ep/close";
import Check from "@iconify-icons/ep/check";

defineOptions({
  name: "Tongji"
});


const formRef = ref();
const tableRef = ref();
const contentRef = ref();
const batchItem = ref('1')
const size = ref("small");
const {
  form, isShow, curRow, loading, columns, exportExcel,salesman_arr,filterData,
  rowStyle, statusList, selectedNum, onSelectionCancel, onbatchAct,diyBiliChangeAble,handleSaveDiyBili,
  dataList, isLinkage, pagination, isExpandAll, isSelectAll, treeSearchValue,
  onSearch, shopList,searchCondList,
  resetForm, openDialog, handleMenu,  handleSave, handleDelete, filterMethod, transformI18n, onQueryChanged, handleSizeChange, handleCurrentChange,handleSelectionChange
} = useAccount(tableRef);

onMounted(() => {
  useResizeObserver(contentRef, async () => {
    await nextTick();
  });
});
</script>

<template>
  <div class="main">
    <el-form ref="formRef" :inline="true" :model="form" :size="size" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto">
      <el-form-item prop="utm_source">
        <el-select v-model="form.utm_source" placeholder="UTM来源" clearable filterable class="!w-[100px]">
<!--          <el-option v-for="(item) in salesman_arr" :label="item.dept?.name+'-'+item.username" :value="item.id" :disabled="item.id==''"/>-->
          <el-option key="facebook" label="Facebook" value="facebook"/>
          <el-option key="instagram" label="Instagram" value="instagram"/>
          <el-option key="tiktok" label="Tiktok" value="tiktok"/>
          <el-option key="youtube" label="youtube" value="youtube"/>
        </el-select>

      </el-form-item>

      <el-form-item  prop="time">
        <el-select v-model="form.search_field2" placeholder="选择时间" class="search_field" style="width: 160px;border-radius:0">
          <el-option label="默认排序(待处理取付款时间，弃单取创建时间)" value="default" />
          <el-option label="按订单创建时间(北京时间)" value="created_at" />
          <el-option label="按订单更新时间(北京时间)" value="updated_at" />
          <el-option label="按订单分配时间(北京时间)" value="diy_allo_at" />
          <el-option label="按订单创建时间(当地时间)" value="created_at_US" />
          <el-option label="按订单更新时间(当地时间)" value="updated_at_US" />
          <el-option label="按订单分配时间(当地时间)" value="diy_allo_at_US" />
        </el-select>
        <el-date-picker
          v-model="form.time" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
          type="daterange" style="width: 200px;border-radius: 0px;border-left: 0;margin-left: -1px;"
          range-separator="~" prefix-icon=""
          start-placeholder="Start date" end-placeholder="End date"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" :icon="useRenderIcon('ri:search-line')" :loading="loading" @click="onSearch"> {{ t("buttons.search") }}
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)"> {{ t("buttons.reset") }}</el-button>
      </el-form-item>
    </el-form>

    <div ref="contentRef" :class="['flex', deviceDetection() ? 'flex-wrap' : '']">
      <PureTableBar
        :class="[isShow && !deviceDetection() ? '!w-[60vw]' : 'w-full']"
        style="transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1)"
        :title="t(route.meta.title)"
        :columns="columns"
        @refresh="onSearch"
      >
        <template #title>
          <el-tabs v-model="form.tab_id" class="bg-bg_color  w-[99/100]  pt-[1px] overflow-auto"  style="margin-top:-8px;" @tab-click="filterData">
            <el-tab-pane label="飞鹰" name="0"></el-tab-pane>
            <el-tab-pane label="公共池子" name="1"></el-tab-pane>
            <el-tab-pane label="私域部门" name="2"></el-tab-pane>
            <el-tab-pane label="其它特殊部门" name="3"></el-tab-pane>
          </el-tabs>
        </template>
        <template v-slot="{ size, dynamicColumns }">
          <pure-table ref="tableRef" align-whole="center" showOverflowTooltip
            table-layout="auto" :loading="loading" :size="size" adaptive
            :row-style="rowStyle" :adaptiveConfig="{ offsetBottom: 108 }"
            :data="dataList" :columns="dynamicColumns" :border="true"
            :header-cell-style="{
              background: 'var(--el-fill-color-light)',
              color: 'var(--el-text-color-primary)'
            }">
            <template #operation="{ row }">
<!--              <el-button v-perms="'order_apply:btn:audit'"  class="reset-margin" link type="primary" :size="size" v-if="form.audit_status==3" @click="onbatchAct('audit_result',row)">-->
<!--                {{ t("buttons.audit") }}-->
<!--              </el-button>-->

<!--              <el-popconfirm :title="t('buttons.deleteConfirm')" @confirm="handleDelete(row)">-->
<!--                <template #reference>-->
<!--                  <el-button v-perms="'order_apply:btn:delete'"  class="reset-margin" link type="primary" :size="size">-->
<!--                    {{ t("buttons.delete") }}-->
<!--                  </el-button>-->
<!--                </template>-->
<!--              </el-popconfirm>-->
            </template>
          </pure-table>
        </template>
        <template #buttons>
          <el-button type="primary" class="" size="small" @click="exportExcel">{{ t("buttons.exportExcel") }}</el-button>
          <el-button type="success" v-perms="'user:btn:set_bili'" :disabled="!diyBiliChangeAble" size="small" @click="handleSaveDiyBili">保存比例设置</el-button>
        </template>
      </PureTableBar>
    </div>
  </div>

</template>

<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
:deep(.el-form--inline .el-form-item) {
  margin-right: 10px;
}
.main-content {
  margin: 24px 24px 0 !important;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
:deep(.search_field .el-select__wrapper) {
  border-radius: 0;border-right: 0;
  margin-right: -1px;
}
:deep(.daibu_tips) {
  background: #bdbebc;
}

:deep(.diy_bili) {
  position: relative;
  width: 100%;
  padding: 6px 0; /* 为显示当前值的元素留出空间 */
}
/* 调整滑块样式，使其轨道宽度100% */
:deep(.el-slider) {
  width: 65%;float:left;margin-right: 12px;
}:deep(.diy_bili .el-input__wrapper) {
  padding: 0 1px;
}
</style>
